﻿using System;
using System.Diagnostics.Contracts;
using System.Windows;
using GIMS.Def.Arguments;
using GIMS.Def.Flags;
using GIMS.GUI.ArgumentControls;

namespace GIMS.GUI.GeneralConfig
{
    public static class ArgumentControlFactory
    {
        public static UIElement CreateConfigControl(Argument argument)
        {
            Contract.Requires(null != argument);
            UIElement configControl = null;

            switch (argument.Type)
            {
                case ArgumentType.append:
                    configControl = CreateAppendControl(argument);
                    break;
                case ArgumentType.color:
                    configControl = CreateColorControl(argument);
                    break;
                case ArgumentType.geometry:
                    configControl = CreateGeometryControl(argument);
                    break;
                case ArgumentType.gravity:
                    configControl = CreateGravityControl(argument);
                    break;
                case ArgumentType.draw:
                    configControl = CreateDrawControl(argument);
                    break;
                case ArgumentType.number:
                    configControl = CreateNumberControl(argument);
                    break;
                case ArgumentType.literal:
                    configControl = CreateLiteralControl(argument);
                    break;
                case ArgumentType.path:
                    configControl = CreatePathControl(argument);
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
            return configControl;
        }

        private static UIElement CreatePathControl(Argument argument)
        {
            var pathArgument = (PathArgument)argument;
            var pathArgumentControlViewModel = new PathArgumentControlViewModel(pathArgument);
            var configControl = new PathArgumentControl(pathArgumentControlViewModel);
            return configControl;
        }

        private static UIElement CreateColorControl(Argument argument)
        {
            var colorArgument = (ColorArgument)argument;
            var colorArgumentControlViewModel = new ColorArgumentControlViewModel(colorArgument);
            var configControl = new ColorArgumentControl(colorArgumentControlViewModel);
            return configControl;
        }

        private static UIElement CreateAppendControl(Argument argument)
        {
            var appendArgument = (AppendArgument)argument;
            var appendArgumentControlViewModel = new AppendArgumentControlViewModel(appendArgument);
            var configControl = new AppendArgumentControl(appendArgumentControlViewModel);
            return configControl;
        }

        private static UIElement CreateGeometryControl(Argument argument)
        {
            var geometryArgument = (GeometryArgument)argument;
            var geometryArgumentControlViewModel = new GeometryArgumentControlViewModel(geometryArgument);
            var geometryArgumentControl = new GeometryArgumentControl(geometryArgumentControlViewModel);
            return geometryArgumentControl;
        }

        private static UIElement CreateGravityControl(Argument argument)
        {
            var gravityArgument = (GravityArgument)argument;
            var gravityArgumentControlViewModel = new GravityArgumentControlViewModel(gravityArgument);
            var configControl = new GravityArgumentControl(gravityArgumentControlViewModel);
            return configControl;
        }

        private static UIElement CreateDrawControl(Argument argument)
        {
            var drawArgument = (DrawArgument)argument;
            var drawArgumentControlViewModel = new DrawArgumentControlViewModel(drawArgument);
            var configControl = new DrawArgumentControl(drawArgumentControlViewModel);
            return configControl;
        }

        private static UIElement CreateNumberControl(Argument argument)
        {
            var numberArgument = (NumberArgument)argument;
            var numberArgumentControlViewModel = new NumberArgumentControlViewModel(numberArgument);
            var configControl = new NumberArgumentControl(numberArgumentControlViewModel);
            return configControl;
        }

        private static UIElement CreateLiteralControl(Argument argument)
        {
            var literalArgument = (LiteralArgument)argument;
            var literalArgumentControlViewModel = new LiteralArgumentControlViewModel(literalArgument);
            var configControl = new LiteralArgumentControl(literalArgumentControlViewModel);
            return configControl;
        }
    }
}
